###
 # @Company: TWL
 # @Author: xue jian
 # @Email: xuejian@kanzhun.com
 # @Date: 2020-07-06 20:30:00
### 
#!/bin/bash

date=$1
day=`date -d "$date" +%Y%m%d`

#outpath=/data3/training_data/flash_data/${date}
outpath=/data2/training_data/flash_data/${date}
if [ ! -d $outpath ]; then
    mkdir -p ${outpath}
fi

#hive -e "select geek_id, exp_id, if(length(geek_position) <= 0, -3, coalesce(geek_position, -3)) as geek_position, if(length(geek_degree) <= 0, 201, coalesce(geek_degree, 201)) as geek_degree, if(length(geek_school_level) <= 0, -1, coalesce(geek_school_level, -1)) as geek_school_level, if(length(geek_cmp_level) <= 0, 0, coalesce(geek_cmp_level, 0)) as geek_cmp_level, if(length(geek_workyears) <= 0, 0, coalesce(geek_workyears, 0)) as geek_workyears, if(length(el) <= 0, 0, coalesce(el, 0)) as el, if(length(eh) <= 0, 0, coalesce(eh, 0)) as eh, boss_id, job_id, if(length(boss_position) <= 0, -3, coalesce(boss_position, -3)) as boss_position, if(length(job_degree) <= 0, 201, coalesce(job_degree, 201)) as job_degree, if(length(job_workyears) <= 0, 101, coalesce(job_workyears, 101)) as job_workyears, if(length(boss_cmp_level) <= 0, 0, coalesce(boss_cmp_level, 0)) as boss_cmp_level, if(length(jl) <= 0, 0, coalesce(jl, 0)) as jl, if(length(jh) <= 0, 0, coalesce(jh, 0)) as jh, deal_type, list_time, pmod(datediff('${date}', '1920-01-01') - 3, 7) as day_of_week from arc.geekrec_train_rtf_all where ds = '${date}' order by list_time limit 2000000000;" > ${outpath}/out
#hive -e "select geek_id, exp_id, if(length(geek_position) <= 0, -3, coalesce(geek_position, -3)) as geek_position, if(length(geek_degree) <= 0, 201, coalesce(geek_degree, 201)) as geek_degree, if(length(geek_school_level) <= 0, -1, coalesce(geek_school_level, -1)) as geek_school_level, if(length(geek_cmp_level) <= 0, 0, coalesce(geek_cmp_level, 0)) as geek_cmp_level, if(length(geek_workyears) <= 0, 0, coalesce(geek_workyears, 0)) as geek_workyears, if(length(el) <= 0, 0, coalesce(el, 0)) as el, if(length(eh) <= 0, 0, coalesce(eh, 0)) as eh, boss_id, job_id, if(length(boss_position) <= 0, -3, coalesce(boss_position, -3)) as boss_position, if(length(job_degree) <= 0, 201, coalesce(job_degree, 201)) as job_degree, if(length(job_workyears) <= 0, 101, coalesce(job_workyears, 101)) as job_workyears, if(length(boss_cmp_level) <= 0, 0, coalesce(boss_cmp_level, 0)) as boss_cmp_level, if(length(jl) <= 0, 0, coalesce(jl, 0)) as jl, if(length(jh) <= 0, 0, coalesce(jh, 0)) as jh, deal_type, list_time, pmod(datediff('${date}', '1920-01-01') - 3, 7) as day_of_week from mining.geekrec_train_ffm where ds = '${date}' order by list_time limit 2000000000;" > ${outpath}/out

hive -e "select geek_id, exp_id, geek_position, geek_degree, geek_school_level, geek_cmp_level, geek_workyears, el, eh, boss_id, job_id, boss_position, job_degree, job_workyears, boss_cmp_level, jl, jh, deal_type, list_time, day_of_week from 
  (select geek_id, exp_id, if(length(geek_position) <= 0, -3, coalesce(geek_position, -3)) as geek_position, if(length(geek_degree) <= 0, 201, coalesce(geek_degree, 201)) as geek_degree, if(length(geek_school_level) <= 0, -1, coalesce(geek_school_level, -1)) as geek_school_level, if(length(geek_cmp_level) <= 0, 0, coalesce(geek_cmp_level, 0)) as geek_cmp_level, if(length(geek_workyears) <= 0, 0, coalesce(geek_workyears, 0)) as geek_workyears, if(length(el) <= 0, 0, coalesce(el, 0)) as el, if(length(eh) <= 0, 0, coalesce(eh, 0)) as eh, boss_id, job_id, if(length(boss_position) <= 0, -3, coalesce(boss_position, -3)) as boss_position, if(length(job_degree) <= 0, 201, coalesce(job_degree, 201)) as job_degree, if(length(job_workyears) <= 0, 101, coalesce(job_workyears, 101)) as job_workyears, if(length(boss_cmp_level) <= 0, 0, coalesce(boss_cmp_level, 0)) as boss_cmp_level, if(length(jl) <= 0, 0, coalesce(jl, 0)) as jl, if(length(jh) <= 0, 0, coalesce(jh, 0)) as jh, deal_type, list_time, pmod(datediff('${date}', '1920-01-01') - 3, 7) as day_of_week from arc.geekrec_train_rtf_all where ds = '${date}' and deal_type not in ('list', 'det')
  union all
  select geek_id, exp_id, if(length(geek_position) <= 0, -3, coalesce(geek_position, -3)) as geek_position, if(length(geek_degree) <= 0, 201, coalesce(geek_degree, 201)) as geek_degree, if(length(geek_school_level) <= 0, -1, coalesce(geek_school_level, -1)) as geek_school_level, if(length(geek_cmp_level) <= 0, 0, coalesce(geek_cmp_level, 0)) as geek_cmp_level, if(length(geek_workyears) <= 0, 0, coalesce(geek_workyears, 0)) as geek_workyears, if(length(el) <= 0, 0, coalesce(el, 0)) as el, if(length(eh) <= 0, 0, coalesce(eh, 0)) as eh, boss_id, job_id, if(length(boss_position) <= 0, -3, coalesce(boss_position, -3)) as boss_position, if(length(job_degree) <= 0, 201, coalesce(job_degree, 201)) as job_degree, if(length(job_workyears) <= 0, 101, coalesce(job_workyears, 101)) as job_workyears, if(length(boss_cmp_level) <= 0, 0, coalesce(boss_cmp_level, 0)) as boss_cmp_level, if(length(jl) <= 0, 0, coalesce(jl, 0)) as jl, if(length(jh) <= 0, 0, coalesce(jh, 0)) as jh, deal_type, list_time, pmod(datediff('${date}', '1920-01-01') - 3, 7) as day_of_week from arc.geekrec_train_rtf_all where ds = '${date}' and deal_type in ('list', 'det') and rand() >= 0.96
  ) t order by list_time limit 2000000000;" > ${outpath}/out

chmod -R 777 ${outpath}

cd /data1/arc_six/transfer_geek
#cat ${outpath}/out | ./transfer_flash /data3/training_data/flash_fid_data/${date} >> /data1/arc_six/transfer_geek/result
cat ${outpath}/out | ./transfer_flash /data2/training_data/flash_fid_data/${date} >> /data1/arc_six/transfer_geek/result